package com.zjy.web.domain.model;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    public static final int SUCCESS_CODE = 1;
    public static final int FAIL = 500;
    private static final String SUCCESS_MSG = "操作成功";
    private static final String FAIL_MSG = "系统异常";

    /**
     * 状态码
     */
    private int code;

    /**
     * 数据
     */
    private T data;

    /**
     * 信息
     */
    private String message;

    public static <T> Result<T> SUCCESS(T t) {
        return CREATE(SUCCESS_CODE, t, SUCCESS_MSG);
    }

    public static <T> Result<T> SUCCESS() {
        return SUCCESS(null);
    }

    public static <T> Result<T> CREATE(int code, String message) {
        return CREATE(code, null, message);
    }

    public static <T> Result<T> FAIL(String message) {
        return CREATE(FAIL, message);
    }

    public static <T> Result<T> FAIL() {
        return CREATE(FAIL, FAIL_MSG);
    }

    public static <T> Result<T> CREATE(int code, T t, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setData(t);
        result.setMessage(message);
        return result;
    }

}
